export const detectMobile = () => {
    const { userAgent } = navigator;
    const mobileKeywords = ["Mobi", "Android", "iPhone", "iPad", "iPod", "Windows Phone"];
    console.log(
        "obileKeywords1.some(keyword => userAgent.includes(keyword))",
        mobileKeywords.some((keyword) => userAgent.includes(keyword))
    );
    if (mobileKeywords.some((keyword) => userAgent.includes(keyword))) {
        return true;
    }

    const screenWidth =
        window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    const isSmallScreen = screenWidth <= 768;

    return isSmallScreen;
}

export const download = (url, name = '') => {
    const isWeChatBrowser = /MicroMessenger/i.test(navigator.userAgent);

    if (!isWeChatBrowser) {
        // 非微信环境直接使用 a 标签下载
        const a = document.createElement('a');
        a.href = url;
        a.download = name;
        a.style.display = 'none';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(a.href);
    } else {
        // 微信环境提示用户使用系统浏览器
        alert('请在系统浏览器中打开此链接以下载文件。');
        // 打开系统浏览器
        window.location.href = url;
    }
}


